<template>
  <div class="doc-header">
    <div class="header-container">
      <div class="header-left">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/knowledge' }">知识空间</el-breadcrumb-item>
          <el-breadcrumb-item>{{ currentSpace.FTitle }}</el-breadcrumb-item>
          <el-breadcrumb-item v-if="currentDoc">{{ currentDoc.FTitle }}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="header-right">
        <!-- <el-button
          size="small"
          @click="onToggleFavorite"
          :icon="currentSpace.FIsStarred ? 'StarFilled' : 'Star'"
          :loading="favoriteLoading"
          :type="currentSpace.FIsStarred ? 'warning' : ''"
          class="action-btn"
        >
          {{ currentSpace.FIsStarred ? "已收藏" : "收藏" }}
        </el-button> -->
        <el-button size="small" @click="onToggleCommentPanel" class="action-btn">
          <el-icon><ChatDotRound /></el-icon>
          <span>{{ showCommentPanel ? "隐藏评论" : "显示评论" }}</span>
        </el-button>
        <el-dropdown @command="onCommand" trigger="click" v-if="isAdmin">
          <el-button size="small" class="more-btn">
            更多操作<el-icon class="el-icon--right"><ArrowDown /></el-icon>
          </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="edit" :disabled="!currentDoc">
                <el-icon><Edit /></el-icon>编辑文档
              </el-dropdown-item>
              <!-- <el-dropdown-item command="history">
                <el-icon><Clock /></el-icon>历史版本
              </el-dropdown-item> -->
              <!-- <el-dropdown-item command="export" divided>
                <el-icon><Download /></el-icon>导出PDF
              </el-dropdown-item> -->
              <el-dropdown-item command="share">
                <el-icon><Share /></el-icon>分享链接
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ArrowDown, ChatDotRound, Edit, Share } from "@element-plus/icons-vue";
import type { PropType } from "vue";
import type { Space } from "@/api/interface/space";
import type { Doc } from "@/api/interface/doc";

type MoreCommand = "edit" | "history" | "export" | "share";

const emit = defineEmits<{
  (e: "toggleFavorite"): void;
  (e: "toggleCommentPanel"): void;
  (e: "moreCommand", cmd: MoreCommand): void;
}>();

defineProps({
  currentSpace: {
    type: Object as PropType<Space.SpaceItem>,
    required: true
  },
  currentDoc: {
    type: Object as PropType<Doc.DocNode | null>,
    default: null
  },
  showCommentPanel: {
    type: Boolean,
    required: true
  },
  favoriteLoading: {
    type: Boolean,
    required: true
  },
  isAdmin: {
    type: Boolean,
    required: true
  }
});

// const onToggleFavorite = () => {
//   emit("toggleFavorite");
// };

const onToggleCommentPanel = () => {
  emit("toggleCommentPanel");
};

const onCommand = (cmd: MoreCommand) => {
  emit("moreCommand", cmd);
};
</script>

<style scoped lang="scss">
.doc-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  height: 60px;
  background-color: #ffffff;
  border-bottom: 1px solid rgb(0 0 0 / 5%);
}
.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 24px;
}
.header-left {
  .el-breadcrumb {
    font-size: 15px;
    :deep(.el-breadcrumb__inner) {
      font-weight: 500;
      color: var(--el-text-color-regular);
      transition: color 0.2s;
      &:hover {
        color: var(--el-color-primary);
      }
    }
    :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
      font-weight: 600;
      color: var(--el-text-color-primary);
    }
  }
}
.header-right {
  display: flex;
  gap: 12px;
  align-items: center;
  .action-btn {
    padding: 8px 12px;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s;
    &:hover {
      transform: translateY(-1px);
    }
    .el-icon {
      margin-right: 6px;
    }
  }
  .more-btn {
    padding: 8px 12px;
    font-weight: 500;
    border-radius: 6px;
  }
}
:deep(.el-dropdown-menu__item) {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  font-size: 14px;
  .el-icon {
    margin-right: 8px;
    font-size: 16px;
  }
}

@media (width <= 768px) {
  .header-container {
    padding: 0 16px;
  }
  .header-right {
    gap: 8px;
    .action-btn span {
      display: none;
    }
  }
}
</style>
